package com.example.demo.Controller;

import com.example.demo.Controller.vo.shangpin;
import com.example.demo.Service.TProductService;
import com.example.demo.entity.TProduct;
import com.example.demo.entity.User;
import com.example.demo.utils.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/TProduct")
public class TProductController {
    private TProductService tP;
@Autowired
    public void settP(TProductService tP) {
        this.tP = tP;
    }
    @RequiresPermissions("user:add")
    @PostMapping("list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize,
                       @RequestBody shangpin shang
    ){
        if (shang.getMax() == null || "".equals(shang.getMax())) {
            shang.setMax("9999-08-02T16:00:00.000Z");
        }
        if (shang.getMin() == null || "".equals(shang.getMin())) {
            shang.setMin("0000-08-02T16:00:00.000Z");
        }
        PageHelper.startPage((pageNum==null || pageNum==0)?1:pageNum, pageSize==null?2:pageSize);
        PageInfo<TProduct> page = new PageInfo<>(tP.list(shang));
        return Result.ok().data("TProduct",page);
    }

}
